package com.hs.bai.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hs.bai.pojo.Order;
import com.hs.bai.service.IAddrinfoService;
import com.hs.bai.pojo.Addrinfo;
import com.hs.bai.service.IOrderService;
import com.hs.bai.service.IOrderbasicinfoService;
import com.hs.dto.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 地址信息 前端控制器
 * </p>
 *
 * @author Dingkun Bai
 * @since 2022-06-13
 */
@CrossOrigin
@RestController
@RequestMapping("/addrinfo")
@Api(tags = "订单地址信息模块")
public class AddrinfoController {

    @Autowired
    private IAddrinfoService addrinfoService;
    @Autowired
    private IOrderService orderService;

    /**
     * 添加订单地址信息
     * @param addrinfo
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加订单地址信息")
    public ResultBean addBasicOrderInfo(@RequestBody Addrinfo addrinfo){
        if (addrinfo != null) {
            return addrinfoService.saveAddInfo(addrinfo);
        }
        return ResultBean.ERROR("添加失败！");
    }

    /**
     * 修改订单地址信息
     * @param addrinfo
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("添加订单地址信息")
    public ResultBean updateBasicOrderInfo(@RequestBody Addrinfo addrinfo){
        if (addrinfo != null) {
            return addrinfoService.updateAdd(addrinfo);
        }
        return ResultBean.ERROR("修改失败！");
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/find/{id}")
    public ResultBean findById(@PathVariable String id){
        Order order = orderService.getById(id);
        Addrinfo addrinfo = addrinfoService.getById(order.getTAId());
        ResultBean ok = ResultBean.OK();
        ok.setData(addrinfo);
        return ok;
    }

}
